{include file="common/head"/}
<div class="main-container" id="main-container">
    <script type="text/javascript">
        try{ace.settings.check('main-container' , 'fixed')}catch(e){}
    </script>
    {include file="common/left"}
    <div class="main-content">
        <div class="main-content-inner">
            {include file="common/header_nav"}
            <div class="page-content">
                <div class="row maintop">
                    <div class="col-xs-12 col-sm-2">
                        <button class="btn btn-xs btn-danger" data-toggle="modal" data-target="#myModal">
                            <i class="ace-icon fa fa-bolt bigger-110"></i>
                            添加会员组
                        </button>
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->
                        <div class="row">
                            <div class="col-xs-12">
                                <form id="groupOrder" name="groupOrder" method="post" action="{:url('groupOrder')}">
                                <div class="table-responsive">
                                    <table id="simple-table" class="table table-striped table-bordered table-hover center">
                                        <thead>
                                        <tr>
                                            <th class="center">ID</th>
                                            <th class="center">会员组名称</th>
                                            <th class="center visible-lg visible-md">满足积分条件</th>
                                            <th class="center">状态</th>
                                            <th class="center">排序</th>
                                            <th class="center" style="border-right:#CCC solid 1px;">操作</th>
                                        </tr>
                                        </thead>

                                        <tbody>
                                        {volist name="member_group_list" id="v"}
                                        <tr>
                                            <td>{$v.group_id}</td>
                                            <td>{$v.name}</td>
                                            <td class="visible-lg visible-md">{$v.bomlimit} - {$v.toplimit} 积分</td>
                                            <td>
                                                {if condition='$v["open"] eq 1'}
                                                <a class="red" href="javascript:;" onclick="return stateyes({$v.group_id});" title="已开启">
                                                    <div id="zt{$v.group_id}">
                                                        <button class="btn btn-minier btn-yellow">状态开启</button>
                                                    </div>
                                                </a>
                                                {else/}
                                                <a class="red" href="javascript:;" onclick="return stateyes({$v.group_id});" title="已禁用">
                                                    <div id="zt{$v.group_id}">
                                                        <button class="btn btn-minier btn-danger">状态禁用</button>
                                                    </div>
                                                </a>
                                                {/if}
                                            </td>
                                            <td>
                                                <input name="{$v.group_id}" value=" {$v.sort}" class="list_order"/>
                                            </td>
                                            <td>
                                                <div class="action-buttons">
                                                    <a class="green" href="javascript:;" onclick="return member_group_edit({$v.group_id});" title="修改">
                                                        <i class="ace-icon fa fa-pencil bigger-130"></i>
                                                    </a>
                                                    <a class="red" href="javascript:;" onclick="return del({$v.group_id});" title="删除">
                                                        <i class="ace-icon fa fa-trash-o bigger-130"></i>
                                                    </a>
                                                </div>
                                            </td>
                                        </tr>
                                        {/volist}
                                        <tr>
                                            <td colspan="8" align="left">
                                                <button type="submit" id="btnorder" class="btn btn-white btn-yellow btn-sm">
                                                    排序
                                                </button>
                                            </td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                                </form>
                            </div><!-- /.span -->
                        </div><!-- /.row -->
                    </div><!-- /.col -->
                </div><!-- /.row -->
            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->
    {include file="common/foot" /}
</div><!-- /.main-container -->

<!-- 显示模态框（Modal） -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <form class="form-horizontal" name="groupAdd" id="groupAdd" method="post" action="{:url('groupAdd')}">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h4 class="modal-title">添加会员组</h4>
                </div>
                <div class="modal-body">
                    <div class="row">
                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right" for="name">会员组名称： </label>
                                <div class="col-sm-10">
                                    <input type="text" name="name" id="name" placeholder="输入会员组名称" class="col-xs-10 col-sm-5"/>
                                </div>
                            </div>
                            <div class="space-4"></div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right" for="bomlimit">积分条件： </label>
                                <div class="col-sm-10">
                                    <span class="input-icon">
                                        <input type="text" id="bomlimit" name="bomlimit" placeholder="输入下限积分"/>
                                        <i class="ace-icon fa fa-leaf blue"></i>
                                    </span>

                                    <span class="input-icon input-icon-right">
                                        <input type="text" id="toplimit" name="toplimit" placeholder="输入上限积分"/>
                                        <i class="ace-icon fa fa-leaf green"></i>
                                    </span>
                                </div>
                            </div>
                            <div class="space-4"></div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right" for="sort">
                                    排序： </label>
                                <div class="col-sm-10">
                                    <input type="text" name="sort" id="sort" value="50" class="col-xs-10 col-sm-3"/>
                                    <span class="lbl">&nbsp;&nbsp;<span class="red">*</span>从小到大排序</span>
                                </div>
                            </div>
                            <div class="space-4"></div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right" for="open">是否开启： </label>
                                <div class="col-sm-10" style="padding-top:5px;">
                                    <input name="open" id="open" value="1" class="ace ace-switch ace-switch-4 btn-flat" type="checkbox"/>
                                    <span class="lbl">&nbsp;&nbsp;默认关闭</span>
                                </div>
                            </div>
                            <div class="space-4"></div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="submit" class="btn btn-primary">
                        提交保存
                    </button>
                    <button class="btn btn-info" type="reset">
                        重置
                    </button>
                    <button type="button" class="btn btn-default" data-dismiss="modal">
                        关闭
                    </button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </form>
</div><!-- /.modal -->

<!-- 显示模态框（Modal） -->
<div class="modal fade in" id="myModaledit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-backdrop fade in" id="gbbb" style="height: 100%;"></div>
    <form class="form-horizontal" name="groupUpdate" id="groupUpdate" method="post" action="{:url('member/groupUpdate')}">
        <input type="hidden" name="group_id" id="editmember_group_id" value=""/>
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" id="gb" data-dismiss="modal" aria-hidden="true">×
                    </button>
                    <h4 class="modal-title" id="myModalLabel">
                        修改用户组
                    </h4>
                </div>
                <div class="modal-body">
                    <div class="row">
                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right" for="editmember_group_name">会员组名称： </label>
                                <div class="col-sm-10">
                                    <input type="text" name="name" id="editmember_group_name" value="" class="col-xs-10 col-sm-5"/>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right" for="editmember_group_bomlimit">积分条件： </label>
                                <div class="col-sm-10">
                                        <span class="input-icon">
                                            <input type="text" id="editmember_group_bomlimit" name="bomlimit" placeholder="输入下限积分"/>
                                            <i class="ace-icon fa fa-leaf blue"></i>
                                        </span>
                                        <span class="input-icon input-icon-right">
                                            <input type="text" id="editmember_group_toplimit" name="toplimit" placeholder="输入上限积分"/>
                                            <i class="ace-icon fa fa-leaf green"></i>
                                        </span>
                                </div>
                            </div>
                            <div class="space-4"></div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right" for="editmember_group_order">排序： </label>
                                <div class="col-sm-10">
                                    <input type="text" name="sort" id="editmember_group_order" value="50" class="col-xs-10 col-sm-3"/>
                                    <span class="lbl">&nbsp;&nbsp;<span class="red">*</span>从小到大排序</span>
                                </div>
                            </div>
                            <div class="space-4"></div>

                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="submit" class="btn btn-primary">提交保存</button>
                    <button type="button" class="btn btn-default" id="gbb">关闭</button>
                </div>
            </div>
        </div>
    </form>
</div>

<script>
    function del(id) {
        layer.confirm('你确定要删除吗？', {icon: 3}, function (index) {
            layer.close(index);
            window.location.href = "{:url('groupDel')}?group_id=" + id;
        });
    }

    function stateyes(id) {
        $.post('{:url("groupState")}', {id: id}, function (data) {
            if (data.status) {
                if (data.info == '状态禁止') {
                    var a = '<button class="btn btn-minier btn-danger">状态禁用</button>'
                    $('#zt' + id).html(a);
                    layer.msg(data.info, {icon: 5});
                    return false;
                } else {
                    var b = '<button class="btn btn-minier btn-yellow">状态开启</button>'
                    $('#zt' + id).html(b);
                    layer.msg(data.info, {icon: 6});
                    return false;
                }
            }
        });
        return false;
    }

    //修改模态框状态
    $(document).ready(function () {
        $("#myModaledit").hide();
        $("#gb").click(function () {
            $("#myModaledit").hide(200);
        });
        $("#gbb").click(function () {
            $("#myModaledit").hide(200);
        });
        $("#gbbb").click(function () {
            $("#myModaledit").hide(200);
        });
    });

    function member_group_edit(val) {
        $.post('{:url("groupEdit")}', {group_id: val}, function (data) {
            if (data.status == 1) {
                $(document).ready(function () {
                    $("#myModaledit").show(300);
                    $("#editmember_group_id").val(data.group_id);
                    $("#editmember_group_name").val(data.name);
                    $("#editmember_group_open").val(data.open);
                    $("#editmember_group_toplimit").val(data.toplimit);
                    $("#editmember_group_bomlimit").val(data.bomlimit);
                    $("#editmember_group_order").val(data.sort);
                });
            }
        });
        return false;
    }


    $(function () {
        $('#groupAdd').ajaxForm({
            beforeSubmit: checkForm, // 此方法主要是提交前执行的方法，根据需要设置
            success: complete, // 这是提交后的方法
            dataType: 'json'
        });

        function checkForm() {

            if ('' == $.trim($('#name').val())) {
                layer.alert('会员组名称不能为空', {icon: 5}, function (index) {
                    layer.close(index);
                    $('#name').focus();
                });
                return false;
            }

            if ('' == $.trim($('#bomlimit').val())) {
                layer.alert('会员组积分下限不能为空', {icon: 5}, function (index) {
                    layer.close(index);
                    $('#bomlimit').focus();
                });
                return false;
            }

            if ('' == $.trim($('#toplimit').val())) {
                layer.alert('会员组积分上限不能为空', {icon: 5}, function (index) {
                    layer.close(index);
                    $('#toplimit').focus();
                });
                return false;
            }
        }
        function complete(data) {
            if (data.status == 1) {
                layer.alert(data.info, {icon: 6}, function (index) {
                    layer.close(index);
                    window.location.href = data.url;
                });
            } else {
                layer.alert(data.info, {icon: 5}, function (index) {
                    layer.close(index);
                    window.location.href = data.url;
                });
                return false;
            }
        }
    });


    $(function () {
        $('#groupUpdate').ajaxForm({
            beforeSubmit: checkForm, // 此方法主要是提交前执行的方法，根据需要设置
            success: complete, // 这是提交后的方法
            dataType: 'json'
        });

        function checkForm() {
            if ('' == $.trim($('#editmember_group_name').val())) {
                layer.alert('会员组名称不能为空', {icon: 5}, function (index) {
                    layer.close(index);
                    $('#member_group_name').focus();
                });
                return false;
            }

            if ('' == $.trim($('#editmember_group_bomlimit').val())) {
                layer.alert('会员组积分下限不能为空', {icon: 5}, function (index) {
                    layer.close(index);
                    $('#editmember_group_bomlimit').focus();
                });
                return false;
            }

            if ('' == $.trim($('#editmember_group_toplimit').val())) {
                layer.alert('会员组积分上限不能为空', {icon: 5}, function (index) {
                    layer.close(index);
                    $('#editmember_group_toplimit').focus();
                });
                return false;
            }
        }
        function complete(data) {
            if (data.status == 1) {
                layer.alert(data.info, {icon: 6}, function (index) {
                    layer.close(index);
                    window.location.href = data.url;
                });
            } else {
                layer.alert(data.info, {icon: 5}, function (index) {
                    layer.close(index);
                    window.location.href = data.url;
                });
                return false;
            }
        }

    });

    //排序提交
    $(function () {
        $('#groupOrder').ajaxForm({
            success: complete, // 这是提交后的方法
            dataType: 'json'
        });

        function complete(data) {
            if (data.status == 1) {
                layer.alert(data.info, {icon: 6}, function (index) {
                    layer.close(index);
                    window.location.href = data.url;
                });
            } else {
                layer.alert(data.info, {icon: 5}, function (index) {
                    layer.close(index);
                    window.location.href = data.url;
                });
            }
        }
    });

</script>
</body>
</html>
